package web.servlet;

import domain.Product;
import persistence.ProductDao;
import persistence.impl.ProductDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class MainFormServlet extends HttpServlet {
    private static final String MAIN_FORM = "/WEB-INF/jsp/catalog/main.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ProductDao productDao = new ProductDaoImpl();
        HttpSession session = req.getSession();

        List<Product> productList= productDao.getProductListByCategory("DOGS");
        session.setAttribute("productList",productList);

        List<Product> productList2= productDao.getProductListByCategory("CATS");
        session.setAttribute("productList2",productList2);

        List<Product> productList3= productDao.getProductListByCategory("BIRDS");
        session.setAttribute("productList3",productList3);

        List<Product> productList4= productDao.getProductListByCategory("REPTILES");
        session.setAttribute("productList4",productList4);

        List<Product> productList5= productDao.getProductListByCategory("FISH");
        session.setAttribute("productList5",productList5);

        req.getRequestDispatcher(MAIN_FORM).forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}


